package com.hlhj.carview.presenter

import android.content.Context
import android.graphics.Color
import com.example.mymvp.mvp.BasePresenter
import com.github.mikephil.charting.charts.ScatterChart
import com.hlhj.carview.Iview.ProfitView
import com.hlhj.carview.module.ProfitModule
import com.github.mikephil.charting.components.XAxis
import android.widget.Toast
import com.example.mymvp.log
import com.github.mikephil.charting.components.Description
import com.hlhj.carview.aty.MainActivity
import com.github.mikephil.charting.listener.OnChartValueSelectedListener
import com.github.mikephil.charting.components.Legend
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.data.ScatterData
import com.github.mikephil.charting.utils.ColorTemplate
import com.github.mikephil.charting.data.ScatterDataSet
import com.hlhj.carview.aty.ProfitAty
import com.hlhj.carview.bean.LastSevenbean
import com.hlhj.carview.bean.MothsBean
import com.hlhj.carview.utils.TimeUtils
import java.util.*


/**
 * Created by Never Fear   on 2018\12\24 0024.
Never More....
 */
class ProfitPresenter :BasePresenter<ProfitModule,ProfitView>(), ProfitView {
    override fun createModule() {
        module=ProfitModule()
        module.lis=this
    }

    fun change(type:Int,c:Context){
        if (type==1){
            getlastSeven(c)
        }else{
            getMonths(c)
        }
    }
    override fun setMonths(mothsBean: MothsBean) {
        view?.setMonths(mothsBean)
    }

    fun getMonths(c:Context){
        module?.getMonths(c)
    }
    fun getlastSeven(c:Context){
        module?.getLastSeven(c)
    }
    override fun setProfit(lastSevenbean: LastSevenbean) {
        view?.setProfit(lastSevenbean)
    }

    fun initChart(scatterChart:ScatterChart, c:Context,values:ArrayList<Entry>){

        scatterChart.xAxis.setValueFormatter { value, axis ->
            log("fhp","${ProfitAty.times.get(value.toInt())?.replace(" ","\n")}")
            if (value%1==0f){
                ProfitAty.times.get(value.toInt())?.replace(" ","\n")
            }
            else{
                " "
            }
        }
        val scatterDataSet = ScatterDataSet(values, "小明每月支出")
        scatterDataSet.setColors(*ColorTemplate.COLORFUL_COLORS)//设置丰富多彩的颜色
        scatterDataSet.setScatterShape(ScatterChart.ScatterShape.CIRCLE)
        val scatterData = ScatterData(scatterDataSet)//生成Scatterdata对象
        scatterData.setValueTextColor(Color.WHITE)
        scatterChart.setData(scatterData)//设置对应数据
        scatterChart.legend.isEnabled=false

        scatterChart.xAxis.textColor=Color.WHITE
        scatterChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM)//设置X轴位置
        scatterChart.getAxisRight().setEnabled(false)//右侧Y轴关闭
        scatterChart.xAxis.axisLineColor=Color.parseColor("#FFFE475C")
        scatterChart.axisLeft.axisLineColor=Color.parseColor("#FFFE475C")
        scatterChart.axisLeft.textColor=Color.WHITE
        scatterChart.getAxisLeft().setAxisMinValue(0.0f)//设置最小Y值
        scatterChart.getXAxis().setGridColor(Color.parseColor("#FFFE475C"))//设置纵向网格线条颜色
        scatterChart.getAxisLeft().setGridColor(Color.parseColor("#FFFE475C"))//设置横向网格颜色
        scatterChart.isDoubleTapToZoomEnabled=false
        scatterChart.setPinchZoom(false)
        val description = Description()
        description.textColor=Color.WHITE
        description.text=""
        scatterChart.setDescription(description)//设置描述内容
        scatterChart.animateXY(1000, 1000)//动画效果

    }
}